<?php
//
//include_once dirname(dirname(__FILE__)) . '/include/common.php';
//$page = isset($_POST["page"]) ? intval($_POST["page"]) : 1;
//
//$core = new core();
//$load_more = 0;
//$zen_order_id = isset($_POST["zen_order_id"]) ? intval($_POST["zen_order_id"]) : 0;
//$type_search = isset($_POST["type_search"]) ? intval($_POST["type_search"]) : 0;
//$key = isset($_POST["key"]) ? addslashes(trim($_POST["key"])) : '';
//if ($type_search != 1 && $type_search != 2) {
//    echo json_encode(array('type' => 1, 'msg' => "Vui lòng chọn cách tìm kiếm!"));
//    die;
//}
//if ($key == "") {
//    echo json_encode(array('type' => 1, 'msg' => "Vui lòng điền từ khóa tìm kiếm!"));
//    die;
//}
//
//$last_customer_order_id = isset($_POST["last_customer_order_id"]) ? intval($_POST["last_customer_order_id"]) : 0;
//if ($core->checkZenOrderByID($zen_order_id)) {
//    $html = '';
//    $total_result = array();
//    if ($type_search == 1) {
//        //search bu product code
//        $is_group_customer = 0;
//    } else {
//        $is_group_customer = 1;
//    }
//    $list_customer_order = $core->getListCustomerOrderByKeyword($zen_order_id, $key, $page, $load_more, $total_result, $is_group_customer, 20);
//    $customer_order_id = 0;
//    $html_total_result='';
//    if ($list_customer_order) {
//        $html_total_result='<table class="table table-striped table-bordered bootstrap-datatable datatable">
//                        <tr>
//                                <th>Tổng số khách hàng</th>
//                                <th>Tổng số sản phẩm</th>
//                                <th>Tổng tiền hàng<br/>(x1000 VNĐ)</th>
//
//                                <th>Tổng cọc<br/>(x1000 VNĐ)</th>
//                                <th>Tổng thừa<br/>(x1000 VNĐ)</th>
//                                <th>Tổng thiếu<br/>(x1000 VNĐ)</th>
//                               
//                            </tr>
//                            <tr>
//                                <td>'.$total_result["total_customer"].'</td>
//                                <td>'.$total_result["total_product"].'</td>
//                                <td>'.number_format($total_result["total_order_money"]/1000).'</td>
//                                <td>'.number_format($total_result["total_payment"]/1000).'</td>
//                                <td>'.number_format($total_result["total_excess_cash"]/1000).'</td>
//                                <td>'.number_format($total_result["total_debit"]/1000).'</td>
//                                
//                            </tr>
//                    </table>';
//        if ($is_group_customer == 0) {
//            //sắp xếp theo ngày ORDER hoặc theo mã sp: không gom nhóm khách được
//
//            foreach ($list_customer_order as $customer_order) {
//
//                if ($customer_order->total_current_money > 0) {
//                    $excess_cash = number_format($customer_order->total_current_money / 1000);
//                    $debit = 0;
//                } else {
//                    $excess_cash = 0;
//                    $debit = number_format($customer_order->total_current_money / 1000);
//                }
//                $html.='<tr class="tr_' . $customer_order->customer_order_id . '">';
//                if ($customer_order->facebook_link != "") {
//                    $html.='<td class="center" ><a href="' . $customer_order->facebook_link . '" target="_blank">' . $customer_order->facebook_name . '</a></td>';
//                } else {
//                    $html.='<td class="center" >' . $customer_order->facebook_name . '</td>';
//                }
//
//                $html.='<td class="center" ><a href="addCustomer.php?id=' . $customer_order->customer_id . '" target="_blank">' . $customer_order->phone . '</a></td>';
//                            if($customer_order->link_web==""){
//                                $html.='<td class="center">' . $customer_order->product_code . '</td>';
//                            }else{
//                                $html.='<td class="center"><a href="' . $customer_order->link_web . '" target="_blank">' . $customer_order->product_code . '</a></td>';
//                            }
//                                
//                            
//                            $html.='<td class="center">' . $customer_order->product_size . '</td>
//                            <td class="center">' . $customer_order->product_num . '</td>
//                            <td class="center">' . $customer_order->product_color . '</td>
//                            <td class="center"><img rel="photo/'.$customer_order->main_photo.'" class="photo_product" src="photo/thumb_photo/200_' . $customer_order->main_photo . '" width="100px"></td>
//                            <td class="center">
//                                <select class="select_order_status" style="width: 120px;" rel="' . $customer_order->id . '" >
//                                    <option value=0 ' . ($customer_order->order_status == 0 ? "selected" : "") . '>Store</option>
//                                    <option value=1 ' . ($customer_order->order_status == 1 ? "selected" : "") . '>Online</option>
//                                    <option value=2 ' . ($customer_order->order_status == 2 ? "selected" : "") . '>Hàng có sẵn</option>
//                                    <option value=3 ' . ($customer_order->order_status == 3 ? "selected" : "") . '>Đã nhận hàng</option>
//                                    <option value=4 ' . ($customer_order->order_status == 4 ? "selected" : "") . '>Đang shipping</option>
//                                    <option value=5 ' . ($customer_order->order_status == 5 ? "selected" : "") . '>Khách đã nhận</option>
//                                    <option value=6 ' . ($customer_order->order_status == 6 ? "selected" : "") . '>Hết hàng</option>
//                                    <option value=7 ' . ($customer_order->order_status == 7 ? "selected" : "") . '>ORDER</option>
//                                    <option value=8 ' . ($customer_order->order_status == 8 ? "selected" : "") . '>Chưa chắc chắn</option>
//                                </select>
//                                <div class="history_status"></div>
//                            </td>
//                            <td class="center">' . number_format($customer_order->product_price / 1000) . '</td>
//                            <td class="center">'.$customer_order->description.'</td>
//                            <td class="center" ></td>
//                            <td class="center" ><a  class="total_payment_link" href="zenPayment.php?id=' . $customer_order->customer_order_id . '">' . number_format($customer_order->total_payment / 1000) . '</a></td>
//                             <td class="center" ></td>
//                            <td class="center" ></td>                           
//                           
//                            
//                            <td class="center" >
//                                
//                            </td>
//                        </tr>';
//            }
//        } else {
//            //gom theo khách
//
//            $customer_order_id = $last_customer_order_id;
//            foreach ($list_customer_order as $customer_order) {
//                if ($customer_order_id != $customer_order->customer_order_id) {
//
//                    $customer_order_id = $customer_order->customer_order_id;
//                    if ($customer_order->total_current_money > 0) {
//                        $excess_cash = number_format($customer_order->total_current_money / 1000);
//                        $debit = 0;
//                    } else {
//                        $excess_cash = 0;
//                        $debit = number_format($customer_order->total_current_money / 1000);
//                    }
//                    $html.='<tr class="tr_' . $customer_order->customer_order_id . '">';
//                    if ($customer_order->facebook_link != "") {
//                        $html.='<td class="center" rowspan="' . $customer_order->total_product . '"><a href="' . $customer_order->facebook_link . '" target="_blank">' . $customer_order->facebook_name . '</a></td>';
//                    } else {
//                        $html.='<td class="center" rowspan="' . $customer_order->total_product . '">' . $customer_order->facebook_name . '</td>';
//                    }
//
//                    $html.='<td class="center" rowspan="' . $customer_order->total_product . '"><a href="addCustomer.php?id=' . $customer_order->customer_id . '" target="_blank">' . $customer_order->phone . '</a></td>';
//                            if($customer_order->link_web==""){
//                                $html.='<td class="center">' . $customer_order->product_code . '</td>';
//                            }else{
//                                $html.='<td class="center"><a href="' . $customer_order->link_web . '" target="_blank">' . $customer_order->product_code . '</a></td>';
//                            }
//                                
//                            
//                            $html.='<td class="center">' . $customer_order->product_size . '</td>
//                            <td class="center">' . $customer_order->product_num . '</td>
//                            <td class="center">' . $customer_order->product_color . '</td>
//                            <td class="center"><img rel="photo/'.$customer_order->main_photo.'" class="photo_product" src="photo/thumb_photo/200_' . $customer_order->main_photo . '" width="100px"></td>
//                            <td class="center">
//                                <select class="select_order_status" style="width: 120px;" rel="' . $customer_order->id . '" >
//                                    <option value=0 ' . ($customer_order->order_status == 0 ? "selected" : "") . '>Store</option>
//                                    <option value=1 ' . ($customer_order->order_status == 1 ? "selected" : "") . '>Online</option>
//                                    <option value=2 ' . ($customer_order->order_status == 2 ? "selected" : "") . '>Hàng có sẵn</option>
//                                    <option value=3 ' . ($customer_order->order_status == 3 ? "selected" : "") . '>Đã nhận hàng</option>
//                                    <option value=4 ' . ($customer_order->order_status == 4 ? "selected" : "") . '>Đang shipping</option>
//                                    <option value=5 ' . ($customer_order->order_status == 5 ? "selected" : "") . '>Khách đã nhận</option>
//                                    <option value=6 ' . ($customer_order->order_status == 6 ? "selected" : "") . '>Hết hàng</option>
//                                    <option value=7 ' . ($customer_order->order_status == 7 ? "selected" : "") . '>ORDER</option>
//                                    <option value=8 ' . ($customer_order->order_status == 8 ? "selected" : "") . '>Chưa chắc chắn</option>
//                                </select>
//                                <div class="history_status"></div>
//                            </td>
//                            <td class="center">' . number_format($customer_order->product_price / 1000) . '</td>
//                            <td class="center">'.$customer_order->description.'</td>
//                            <td class="center" rowspan="' . $customer_order->total_product . '">' . number_format($customer_order->total_order_money / 1000) . '</td>
//                            <td class="center" rowspan="' . $customer_order->total_product . '"><a  class="total_payment_link" href="zenPayment.php?id=' . $customer_order->customer_order_id . '">' . number_format($customer_order->total_payment / 1000) . '</a></td>
//                             <td class="center" rowspan="' . $customer_order->total_product . '">' . $debit . '</td>
//                            <td class="center" rowspan="' . $customer_order->total_product . '">' . $excess_cash . '</td>                           
//                           
//                             <td class="center" rowspan="'.$customer_order->total_product.'">'.$customer_order->order_description.'</td>
//                            <td class="center" rowspan="' . $customer_order->total_product . '">
//                                <a class="btn btn-info btn_edit_customer_order" href="javascript:void(0)" rel="' . $customer_order->customer_order_id . '">
//                                    <i class="icon-edit icon-white"></i>  
//                                    Edit                                            
//                                </a>
//                                <a rel="' . $customer_order->customer_order_id . '" class="btn btn-danger btn_delete_order_detail" href="javascript:void(0)" style=" margin: 10px 0px;">
//                                    <i class="icon-trash icon-white"></i> 
//                                    Delete
//                                </a>
//                            </td>
//                        </tr>';
//                } else {
//
//                    $html.=' <tr class="tr_' . $customer_order->customer_order_id . '">';
//                            if($customer_order->link_web==""){
//                                $html.='<td class="center">' . $customer_order->product_code . '</td>';
//                            }else{
//                                $html.='<td class="center"><a href="' . $customer_order->link_web . '" target="_blank">' . $customer_order->product_code . '</a></td>';
//                            }
//                                
//                            
//                            $html.='<td class="center">' . $customer_order->product_size . '</td>
//                            <td class="center">' . $customer_order->product_num . '</td>
//                            <td class="center">' . $customer_order->product_color . '</td>
//                            <td class="center"><img rel="photo/'.$customer_order->main_photo.'" class="photo_product" src="photo/thumb_photo/200_' . $customer_order->main_photo . '" width="100px"></td>
//                            <td class="center">
//                                <select class="select_order_status" style="width: 120px;" rel="' . $customer_order->id . '">
//                                    <option value=0 ' . ($customer_order->order_status == 0 ? "selected" : "") . '>Store</option>
//                                    <option value=1 ' . ($customer_order->order_status == 1 ? "selected" : "") . '>Online</option>
//                                    <option value=2 ' . ($customer_order->order_status == 2 ? "selected" : "") . '>Hàng có sẵn</option>
//                                    <option value=3 ' . ($customer_order->order_status == 3 ? "selected" : "") . '>Đã nhận hàng</option>
//                                    <option value=4 ' . ($customer_order->order_status == 4 ? "selected" : "") . '>Đang shipping</option>
//                                    <option value=5 ' . ($customer_order->order_status == 5 ? "selected" : "") . '>Khách đã nhận</option>
//                                    <option value=6 ' . ($customer_order->order_status == 6 ? "selected" : "") . '>Hết hàng</option>
//                                    <option value=7 ' . ($customer_order->order_status == 7 ? "selected" : "") . '>ORDER</option>
//                                    <option value=8 ' . ($customer_order->order_status == 8 ? "selected" : "") . '>Chưa chắc chắn</option>
//                                </select>
//                                <div class="history_status"></div>
//                            </td>
//                            <td class="center">' . number_format($customer_order->product_price / 1000) . '</td>
//                            <td class="center">'.$customer_order->description.'</td>
//                        </tr>';
//                }
//            }
//        }
//    }
//
//    $page = $page + 1;
//    echo json_encode(array('type' => 0, 'html' => $html, 'page' => $page, 'load_more' => $load_more, 'last_customer_order_id' => $customer_order_id, 'html_total_result' => $html_total_result));
//    die;
//}
?>